//
//  CRquestMgr.m
//  wanzhaoIM
//
//  Created by liuyuantao on 15/5/29.
//  Copyright (c) 2015年 liuyuantao. All rights reserved.
//

#import "CRequestMgr.h"
#import "CRequestModel.h"
#define KREQUESTLOCKSTR @"requestList"

@interface CRequestMgr()
@property(nonatomic, strong)NSMutableArray *requestList;

@end


@implementation CRequestMgr
+(CRequestMgr *)shareInstance
{
    static CRequestMgr *instance  = nil;
    static dispatch_once_t dispatch_onces;
    if(instance  == nil)
    {
        dispatch_once(&dispatch_onces, ^{
            instance = [[CRequestMgr alloc] init];
        });
    }
    return instance;
}

-(id)init
{
    self = [super init];
    if(self)
    {
        _requestList = [NSMutableArray arrayWithCapacity:10];
    }
    return self;
}


//插入请求
-(BOOL)insertRequestModel:(CRequestModel *)requestModel
{
    if(requestModel == nil)
    {
        return NO;
    }
    
    @synchronized(KREQUESTLOCKSTR)
    {
        [_requestList addObject:requestModel];
    }
    
    return YES;
}

//取出请求
-(CRequestModel *)getRequestModelByRequestId:(int64_t)requestId
{
    CRequestModel *requestModel = nil;
    @synchronized(KREQUESTLOCKSTR)
    {
        for(CRequestModel *index in _requestList)
        {
            if(index == nil)
            {
                continue;
            }
            if(index.requestID == requestId)
            {
                requestModel = index;
                [_requestList removeObject:index];
                break;
            }
        }
    }
    return requestModel;
}
@end
